const {
  get
} = require('./../../utils/request');
Page({
  data: {
    hideFlag: true, //true-隐藏  false-显示
    isMuted: false, //视频播放与停止
    arr: [], //下方列表显示
    videoUrl: '', //顶部列表
    scenicId: '', //扫码进入得景区id
    scenicName: '' //用户输入框输入进行搜索
  },
  onLoad: function (options) {
    if (options && options.shopId) {
      wx.setStorageSync('shopId', options.shopId)
    }
    if (options && options.scenicId) {
      this.setData({
        scenicId: options.scenicId
      })
    }
    get('/scenic/area/getVideos').then(res => {
      let str = res.images;
      this.setData({
        videoUrl: str && str.split(',')[0] || ''
      })
    })
  },
  onShow: function () {
    if (this.data.scenicName) {
      this.srarchFn()
    } else {
      //获取首页参数
      setTimeout(() => {
        get('/scenic/area/scenicSearch2', {
          scenicId: this.data.scenicId
        }).then(res => {
          //图片宽度自适应
          this.setData({
            arr: res || []
          })
        })
      }, 140);
    }
  },
  getValue(e){
    this.setData({
      scenicName: e.detail.value
    })
  },
  //通过搜索框搜索景区
  srarchFn() {
    get('/scenic/area/scenicSearch2', {
      scenicName: this.data.scenicName
    }).then(res => {
      //图片宽度自适应
      this.setData({
        arr: res || []
      })
    })
  },
  toPhotoFn() {
    wx.navigateTo({
      url: '/pages/photos/photos',
    })
  },
  //中文景点
  toPageinfo(e) {
    let id = e.currentTarget.dataset.id
    let price = e.currentTarget.dataset.price
    let scenicSubCounts = e.currentTarget.dataset.scenicsubcounts
    let latitude = e.currentTarget.dataset.latitude
    let longitude = e.currentTarget.dataset.longitude
    wx.navigateTo({
      url: '/pages/pageinfo/pageinfo?id=' + id + '&scenicSubCounts=' + scenicSubCounts + '&price=' + price + '&latitude=' + latitude + '&longitude=' + longitude,
    })
  },
  changeMutedFn() {
    this.setData({
      isMuted: !this.data.isMuted
    })
  },
  //点击放大抖音二维码
  previewImg() {
    wx.previewImage({
      urls: ['/images/44444.png'],
      current: '/images/44444.png'
    })
  },
  onShareAppMessage() {
    return {
      title: '一触即听，景行千里',
      imageUrl: './../../images/share.jpg',
      path: '/pages/index/index?scenicId=' + this.data.scenicId
    }
  },
  onShareTimeline() {
    return {
      title: '一触即听，景行千里',
      query: '/pages/index/index?scenicId=' + this.data.scenicId
    }
  }
})